import request from '@/utils/request'
// import qs from 'qs'

// 获取设备基本信息
export function getBasicInfo (params) {
  var data = fromData(params)
  return request({
    url: '/basic/getInfo',
    method: 'post',
    data
  })
}

// 修改设备名称
export function editBasicName (params) {
  var data = fromData(params)
  return request({
    url: '/basic/editName',
    method: 'post',
    data
  })
}

// 获取设备当前时间
export function getSystemTime (params) {
  var data = fromData(params)
  return request({
    url: '/basic/getSystemTime',
    method: 'post',
    data
  })
}

// 获取NTP校时服务器配置
export function getNtp (params) {
  var data = fromData(params)
  return request({
    url: '/basic/getNtp',
    method: 'post',
    data
  })
}

// 设置设备当前时间
export function setSystemTime (params) {
  var data = fromData(params)
  return request({
    url: '/basic/setSystemTime',
    method: 'post',
    data
  })
}

// 设置NTP校时服务器
export function setNtp (params) {
  var data = fromData(params)
  return request({
    url: '/basic/setNtp',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
